const app = getApp()

const { listApi } = require('../../../api/services/task/index')
Page({
  data: {
    params: { pageNum: 0, pageSize: 10, divideId: '' },
    dataList: [],
    dataMore: true,
    total: 0,
    YHZG_Edit: null,
    value1: '',
    active: '',
  },

  // 筛选
  onChange(e) {
    this.setData({
      active: e.detail,
      'params.divideId': e.detail,
    })
    this.setData({ listData: [], dataMore: true })
    this.getListData()
  },

  async getListData() {
    if (!this.data.dataMore) return

    this.data.params.pageNum++
    const res = await listApi(this.data.params)

    if (res.code != 200) {
      return app.toast(res.msg)
    }
    const newList = [...this.data.dataList, ...res.rows]

    this.setData({
      total: res.total,
      dataList: newList,
      dataMore: newList.length < res.total,
    })
  },

  handleDanger(event) {
    let { item } = event.currentTarget.dataset
    let taskId = item.id
    wx.navigateTo({ url: '/pages/admin/dangersCheck/dangersCheck?taskId=' + taskId }) //管理员用户
  },

  onLoad: function (options) {},

  onShow: function () {
    this.setData({ 'params.pageNum': 0 })
    this.setData({ dataList: [], dataMore: true })
    this.getListData()
    if (wx.getStorageSync('YHZG_Edit')) {
      wx.setNavigationBarTitle({
        title: '隐患排查',
      })
    } else {
      wx.setNavigationBarTitle({
        title: '隐患整改',
      })
    }

    this.setData({ YHZG_Edit: wx.getStorageSync('YHZG_Edit') })
  },

  onReachBottom: function () {
    this.getListData()
  },
})
